home *** CD-ROM | disk | FTP | other *** search
- ////
- //// Launch.c Test tool for SignatureToApp.
- ////
- //// By Jens Alfke ©1991 Apple Computer, Inc. All rights reserved.
- ////
-
- //// This is a little demo tool that shows how to call SignatureToApp.
- //// Usage:
- //// Launch ( [-proc] [-file] [-launch] signature )*
- //// where signature is a 4-character application signature.
- ////
- //// Default behavior is to launch or bring to the front the application with that signature.
- //// Leading flags will modify this:
- //// -proc means only to look for a running process with that signature.
- //// -file means to find a running process or a file, but not launch it
- //// -launch (the default) means to find a running process or find and launch an app.
- //// You can list more than one signature. Each flag modifies the behavior for following
- //// signatures until another flag is found.
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include <Errors.h>
- #include <Memory.h>
-
- #include "SignatureToApp.h"
-
- main( int argc, char *argv[] )
- {
- Boolean foundSignature = false;
- short arg;
- Sig2App_Mode mode = Sig2App_LaunchApplication;
- char *argstr;
- OSType sig;
- ProcessSerialNumber psn;
- FSSpec file;
- Boolean launched;
- OSErr err;
- long len;
-
- if( argc<=1 ) {
- puts("Launch: Finds and/or launches application with given signature");
- return 1;
- }
-
- for( arg=1; arg<argc; arg++ ) {
- argstr = argv[arg];
-
- // Interpret a flag:
-
- if( argstr[0] == '-' ) {
- if( strcmp(argstr,"-proc")==0 )
- mode = Sig2App_FindProcess;
- else if( strcmp(argstr,"-file")==0 )
- mode = Sig2App_FindApplication;
- else if( strcmp(argstr,"-launch")==0 )
- mode = Sig2App_LaunchApplication;
- else {
- fprintf(stderr,"Launch: Unknown flag “%s”\n",argstr);
- return 1;
- }
- continue;
- } else {
-
- // Interpret anything else as an application signature:
-
- foundSignature = true;
- sig = ' ';
- len = strlen(argstr);
- if( len>4 )
- len = 4;
- BlockMove(argstr,&sig,len); // Copy signature
-
- // Here we go. Watch carefully:
-
- err = SignatureToApp(sig, &psn, &file, &launched, mode, launchContinue);
-
- if( err==fnfErr ) {
- fprintf(stderr,"Launch: No application with signature '%.4s' found.\n", &sig);
- return 1;
- } else if( err==procNotFound ) {
- fprintf(stderr,"Launch: No application with signature '%.4s' is running.\n", &sig);
- return 1;
- }else if( err ) {
- fprintf(stderr,"Launch: Error %d (signature '%.4s').\n", err,&sig);
- return 1;
- }
-
- if( mode < Sig2App_LaunchApplication ) {
- printf("'%.4s': PSN= {%d/%d}; File= {vol=%hd, dir=%d, name=%P}\n",
- &sig,
- psn.highLongOfPSN,psn.lowLongOfPSN,
- file.vRefNum, file.parID, file.name);
- }
- }
- }
-
- if( !foundSignature ) {
- fprintf(stderr,"Launch: Missing application signature\n");
- return 1;
- }
- return 0;
- }